package com.domi.controller;

import com.domi.bean.RestfulResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;


@RestController
@RequestMapping("/book-client")
public class BookClientController {

    @Autowired
    private RestTemplate restTemplate; // springboot 默认提供

    @GetMapping("/search/{qryStr}")
    public RestfulResponse search(@PathVariable String qryStr) {
        return restTemplate.getForObject(
                "http://book-center/book/search?q=" + qryStr, RestfulResponse.class);
    }

    @GetMapping("/categories")
    public RestfulResponse categories() {
        return restTemplate.getForObject(
                "http://book-center/book/categories", RestfulResponse.class);
    }

    @GetMapping("/category/{name}")
    public RestfulResponse category(@PathVariable String name) {
        return restTemplate.getForObject(
                "http://book-center/book/category/" + name, RestfulResponse.class);
    }

    @GetMapping("/flight")
    public RestfulResponse flight() {
        return restTemplate.getForObject(
                "http://book-center/book/flight", RestfulResponse.class);
    }

}